package com.douyin.config;

import com.douyin.interceptor.JwtTokenUserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    JwtTokenUserInterceptor jwtTokenUserInterceptor;


    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenUserInterceptor)
                // 1. addPathPatterns: 指定要拦截的路径
                // "/**" 表示拦截所有请求
                .addPathPatterns("/**")

                // 2. excludePathPatterns: 指定要排除(放行)的路径
                .excludePathPatterns(
                        "/user/login",          // 放行登录接口
                        "/user/register",       // 放行注册接口
                        "/user/code",      // 放行发送验证码接口
                        "/doc.html",            // 放行 knife4j 或 swagger 的文档页面
                        "/webjars/**",
                        "/swagger-resources",
                        "/v3/api-docs/**"
                );
    }
}
